import urllib.request
import re
from tokenize import Operator
import pickle

def level1():
    print(str(2**38) + ".html");
    
def level2():
    original = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
    trans = str.maketrans("abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab")
    print(original.translate(trans))
    print("map".translate(trans))
    
def level3():
    page = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/ocr.html')
    contents = str(page.read())
    characters = "".join(re.findall(r'<!--([^-->]*)-->', contents)).replace("\\n", "")
    lcDict = {}
    listChars = list(characters)
    for l in listChars:
        if l in lcDict:
                lcDict[l] +=1
        else:
                lcDict[l]= 1
    sorted_x = sorted(lcDict.items(), key=lambda item: item[1])
    print(sorted_x)
    
def level4():
    page = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/equality.html')
    contents = str(page.read())
    characters = "".join(re.findall(r'<!--(.*)-->', contents))    
    matches = re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', characters)
    print(matches)
    print("Done")#
    
def level5helper(number):
    page = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' + number)  
    pageBytes = page.read()
    contents = str(pageBytes)
    characters = "".join(re.findall('([0-9]*)', contents))
    if len(characters) > 0:
        return characters
    elif contents == "b'Yes. Divide by two and keep going.'":
        return ""
    else:
        return contents

def level5():
    retVal = level5helper("12345")
    while len(retVal) == 0 or re.match("[0-9]+", retVal):
        print(retVal)
        retVal = level5helper(retVal)
    print(retVal) 

def level6():
    favorite_color = pickle.load( open( "C:\\Users\\Matt\\Downloads\\banner.p", "rb" ) )
    for x in favorite_color:
        line = ""
        for y in x:
            line += y[1] * y[0]
        print(line)
    
if __name__ == '__main__':
    level6()